<!--
*@Author: QWP
*@Description: 配置的流程展示
*@Date: 2024-08-15 17:48:29
-->
<template>
  <u-dialog title="流程记录"
    v-bind="$attrs"
    :hideBtns="['submit']"
    wrap-class-name="full-modal"
    @close="dialogClose">
    <template v-if="selFirstItem[props.props.value]">
      <u-flow-tab :show="true"
        activeKey="flow"
        :isAudit="false"
        :open="$attrs['open']"
        :params="{ 
          type: busiType, 
          ...selFirstItem, 
          processInstanceId: selFirstItem[props.props.value]
        }"
        v-bind="$attrs"/>
    </template>
    <template v-else>
      <a-empty description="暂无流程可查看"/>
    </template>
  </u-dialog>
</template>

<script lang='ts' setup>
defineOptions({ name: 'u-act-flowd' })
import { useAttrs, watch, ref, computed  } from 'vue'
import { messageC, nullC } from '@/util/common'
import { cloneDeep } from 'lodash'
const props = withDefaults(
  defineProps<{
    selDatas?: any[],
    props?: object,
    busiType?: string
  }>(),
  {
    props: { value: 'processintsid' }
  }
)

const attrs = useAttrs();

const emits = defineEmits(['update:open'])

const processInstanceId = ref<string>('')

const selFirstItem = computed(() => {
  let tObj = (props.selDatas || []).length > 0 ? props.selDatas[0] : {} 
  let deepObj = cloneDeep(tObj)
  if(attrs.open == false) {
    deepObj[props.props.value] = "";
    deepObj['keyid'] = ''
  }
  return deepObj
})

watch(() => attrs.open, (nva, oval) => {
  if(nva == true && !attrs['processInstanceId']) {
    if((props.selDatas || []).length != 1) {
      messageC("能且只能选择一条数据进行查看!");
      emits('update:open', false)
      return
    }
    processInstanceId.value = nullC(props.selDatas[0][props.props.value])
  }
})

const dialogClose = () => {
  processInstanceId.value = '';
  emits('update:open', false)
}

</script>

<style lang='scss' scoped>
</style>